// about_boolean_functions.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "about_boolean_functions.h"

/// 全局变元控制在头文件中设置。
/// 本代码所有函数均为 var 元布尔函数。
///	主函数 main 打印一个布尔函数的相关信息。


/// 生成一个 M-Mbent 函数
/// 原理：
/// f(x,y) = x \codt \pi(y) + g(y)
/// \pi() 是 置换， g 是任意布尔函数
/// 此处，g(y) = 0, \pi(y) = y
/// f(x,y) = x \cdot y
void M_M_bent(int * f) {
	// var/2 元向量 x y
	int x[var / 2] = { 0 };
	int y[var / 2] = { 0 };
	// 开始构造
	for (int i = 0; i < (1<<var); i++)
	{
		// 向 f 中填入真值表
		f[i] = cdot(x, y, var / 2);

		// 将 x,y 移向下一位。
		bool next_x = false;
		for (int y_i = (var / 2 - 1); y_i > -1; y_i--)
		{
			if (y[y_i] == 0) {
				y[y_i] = 1;
				break;
			}
			else {
				y[y_i] = 0;
				if (y_i == 0)
				{
					next_x = true;
				}
			}			
		}
		if (next_x) {
			for (int x_i = var / 2 - 1; x_i > -1; x_i--)
			{
				if (x[x_i] == 0) {
					x[x_i] = 1;
					break;
				}
				else {
					x[x_i] = 0;
				}
			}
		}
	}
}

int main()
{
	// start
    std::cout << "Hello World!\n";
	// input a boolean function
	//int f[1 << var] = { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,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1,1,0,1,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,0,0,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
	
	int f[1 << var] = { 0 };
	M_M_bent(f);
	
	print_bf(f);

	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
